package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Name;
import com.itheima.pojo.Report;
import com.itheima.pojo.ReportClazzCount;
import com.itheima.pojo.ReportCount;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class ReportServiceimpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Report> genderCount() {
        List<Report> reports = empMapper.genderCount();
        for (Report report : reports) {
            if (report.getName().equals("1")) {
                report.setName("男");
            } else {
                report.setName("女");
            }
        }
        return reports;
    }

    @Override
    public ReportCount JobCount() {
        List<Map<String,Object>> list = empMapper.jobCount();
        log.info(list.toString());
        List<Object> jobList = list.stream().map(l -> l.get("jobname")).toList();
        List<Object> dataList = list.stream().map(t -> t.get("total")).toList();
        return new ReportCount(jobList,dataList);

//        List<Integer> list = empMapper.jobCount();
//        log.info("{数据}",list);
//        TreeMap<String, Integer> map = new TreeMap<>();
//        int a = 0;
//        int b = 0;
//        int c = 0;
//        int d = 0;
//        int e = 0;
//        int f = 0;
//        for (Integer i : list) {
//            if(i==null || i>6){
//                f++;
//                map.put("其他", f);
//                continue;
//            }
//            if (i == 1) {
//                a++;
//                map.put("班主任", a);
//                continue;
//            } else if (i == 2) {
//                b++;
//                map.put("讲师", b);
//                continue;
//            } else if (i == 3) {
//                c++;
//                map.put("学工主管", c);
//                continue;
//            } else if (i == 4) {
//                d++;
//                map.put("教研主管", d);
//                continue;
//            } else if (i == 5) {
//                e++;
//                map.put("咨询师", e);
//                continue;
//            } else if(i==6) {
//                f++;
//                map.put("其他", f);
//            }
//        }
//        Collection<Integer> values = map.values();
//        Set<String> keySet = map.keySet();
//
//        return new ReportCount(keySet, values);
    }

    @Override
    public List<Report> studentCount() {
        List<Report> reports = studentMapper.studentCount();
        for (Report report : reports) {
            if (report.getName().equals("1")) {
                report.setName("初中");
            } else if (report.getName().equals("2")) {
                report.setName("高中");
            } else if (report.getName().equals("3")) {
                report.setName("大专");
            } else if (report.getName().equals("4")) {
                report.setName("本科");
            } else if (report.getName().equals("5")) {
                report.setName("硕士");
            } else if (report.getName().equals("6")) {
                report.setName("博士");
            }

        }
        return reports;
    }

    @Override
    public ReportClazzCount studentCountPop() {
        List<Report> reports = studentMapper.studentCountPop();
        ReportClazzCount reportClazzCount = new ReportClazzCount();
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (Report report : reports) {
            clazzList.add(report.getName());
            dataList.add(report.getValue());
        }
        reportClazzCount.setDataList(dataList);
        reportClazzCount.setClazzList(clazzList);
        return reportClazzCount;
    }
}
